//
//  ByAddressCell.m
//  hutouben_ios
//
//  Created by mc on 16/11/29.
//  Copyright © 2016年 mc. All rights reserved.
//

#import "ByAddressCell.h"
@interface ByAddressCell()
@property (nonatomic, strong) UILabel *phoneLabel;
@property (nonatomic, strong) UILabel *userNameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@end
@implementation ByAddressCell
+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByAddressCell";
    ByAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [self setViews];

    }
    return self;
}

#pragma mark ---创建视图
- (void)setViews{
    //手机号
    _phoneLabel = [[UILabel alloc] init];
    _phoneLabel.textColor = HTB_TEXT_COLOR1;
    _phoneLabel.font = FONT(16);
    _phoneLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:_phoneLabel];

    //名字
    _userNameLabel = [[UILabel alloc] init];
    _userNameLabel.textColor = HTB_TEXT_COLOR1;
    _userNameLabel.font = FONT(16);
    [self addSubview:_userNameLabel];
    
    //详细地址
    _detailLabel = [[UILabel alloc] init];
    _detailLabel.textColor = HTB_TEXT_COLOR2;
    _detailLabel.font = FONT(14);
    [self addSubview:_detailLabel];

}

-(void)setModel:(ByAddressModel *)model{
    _model = model;
    CGFloat width = [model.mobile getSizeOfString:14].width + 20;
    [_phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-30);
        make.top.equalTo(self).offset(15);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    _phoneLabel.text = model.mobile;
    
    
    [_userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.top.equalTo(self).offset(15);
        make.right.equalTo(_phoneLabel.mas_left).offset(- 10);
    }];
    if ([_model.is_default isEqualToString:@"1"]) {
        NSString *detailStr = [NSString stringWithFormat:@"默认%@",model.contactname];
        NSMutableAttributedString *detailInfo = [[NSMutableAttributedString alloc] initWithString:detailStr];
        [detailInfo addAttribute:NSForegroundColorAttributeName value:HTB_THEME_COLOR range:NSMakeRange(0, 2)];
        _userNameLabel.attributedText = detailInfo;
    }else{
        _userNameLabel.text = model.contactname;

    }
    
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.top.equalTo(_userNameLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10 - 30, 20));
    }];
    _detailLabel.text = model.detailinfo;


}

@end
